I'm using one of the online JS editor and it is giving me this below error although when I'm consoling the value of initial it is an array so it should iterate. I' not getting what is wrong with it. Thanks in advance for helping.
let lists = [[1,4,5],[1,3,4],[2,6]];
let output=[];
let initial = lists[0]?lists[0]:[]
output.push(...initial); //giving error here
for(let i=1; i<lists.length; i++) {
curr = output;
next = lists[i];
j=0;k=0;
x=0;
//console.log(j,next,'next')
while(j<next.length) {
if(next[j]<=curr[x]){
output.splice(x,0,next[j]);
j++;
x++;
}else{
if(curr.length>x){
//k++;
x++;
}else{
output.push(...next.slice(j))
break;
}
}
}
}
//console.log(output)